package cn.zk.consumer;

import cn.zk.config.DeathMessageConfig;
import cn.zk.config.RabbitMQConfig;
import cn.zk.domain.MqMessage;
import cn.zk.mapper.MqMessageMapper;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;

/**
 * 监听死信队列，处理延迟任务
 */
@Slf4j
@Component
public class DeathQueueHandler {

    // 监听死信队列，处理延迟任务
    @RabbitListener(queues = {DeathMessageConfig.QUEUE_DEATH})
    public void receive_email(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        log.info("收到死信队列信息===>{}",msg);
        System.out.println("收到死信队列信息===>"+msg);
        // 手动签收
        channel.basicAck(message.getMessageProperties().getDeliveryTag()
                        ,false);
    }

} 